package kinect.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import dll_test.KinectHandler;

/**
 * Servlet implementation class SetAngleServlet
 */
@WebServlet("/SetAngleServlet")
public class SetAngleServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
    KinectHandler kh;
    /**
     * @see HttpServlet#HttpServlet()
     */
    public SetAngleServlet() {
        super();
        // TODO Auto-generated constructor stub
        kh = KinectHandler.getInstance();
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String angleString = (String)request.getParameter("angle");
		int angle = Integer.parseInt(angleString);
		if(angle<=27 && angle>=-27) {
			kh.setAngle(angle);
			response.getWriter().write("S_OK");
		} else {
			response.getWriter().write("E_FAIL");
		}
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String angleString = request.getParameter("angle");
		int angle = Integer.getInteger(angleString);
		if(angle<=27 && angle>=-27) kh.setAngle(angle);
	}

}
